<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="100px" size="medium" class="ry_form">
      <el-form-item label="城市名称" prop="area">
        <el-input
          v-model.trim="queryParams.area"
          placeholder="请输入城市名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="城市编码" prop="areaCode">
        <el-input
          v-model.trim="queryParams.areaCode"
          placeholder="请输入城市编码"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item class="flex_one tr">
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['act:FhMapWeather:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['act:FhMapWeather:edit']"
        >修改</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList" :columns="columns"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="FhMapWeatherList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="城市名称" align="center" prop="area" v-if="columns[0].visible"/>
      <el-table-column label="城市编码" align="center" prop="areaCode" v-if="columns[1].visible"/>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['act:FhMapWeather:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['act:FhMapWeather:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改城市天气管理对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="50%" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="108px" inline class="dialog-form-two">
        <el-form-item label="城市名称" prop="area">
          <el-input v-model.trim="form.area" placeholder="请输入城市名称" />
        </el-form-item>
        <el-form-item label="城市编码" prop="areaCode">
          <el-input v-model.trim="form.areaCode" placeholder="请输入城市编码" />
        </el-form-item>
        <el-form-item label="创建时间" prop="crateTime">
          <el-date-picker clearable size="small"
                        v-model="form.crateTime"
                        type="datetime"
                        value-format="yyyy-MM-ddTHH:mm:ss"
                        placeholder="选择创建时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="用户id" prop="userId">
          <el-input v-model.trim="form.userId" placeholder="请输入用户id" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listFhMapWeather, getFhMapWeather, delFhMapWeather, addFhMapWeather, updateFhMapWeather, exportFhMapWeather } from "@/api/act/fhMapWeather";

export default {
  name: "FhMapWeather",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 城市天气管理表格数据
      FhMapWeatherList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        area: null,
        areaCode: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        area: [
          { required: true, message: "城市名称不能为空", trigger: "blur" }
        ],
        areaCode: [
          { required: true, message: "城市编码不能为空", trigger: "blur" }
        ],
      },
      columns: [
            { key: 1, label: "城市名称", visible:  true  },
            { key: 2, label: "城市编码", visible:  true  },
                 ],
    };
  },
  created() {
    this.getList();
  },
  methods: {
    importCityData() {
      this.loading = true;
      const cityData = [
        { areaCode: "130100", area: "石家庄市" },
        { areaCode: "130200", area: "唐山市" },
        { areaCode: "130300", area: "秦皇岛市" },
        { areaCode: "130400", area: "邯郸市" },
        { areaCode: "130500", area: "邢台市" },
        { areaCode: "130600", area: "保定市" },
        { areaCode: "130700", area: "张家口市" },
        { areaCode: "130800", area: "承德市" },
        { areaCode: "130900", area: "沧州市" },
        { areaCode: "131000", area: "廊坊市" },
        { areaCode: "131100", area: "衡水市" },
        { areaCode: "110000", area: "北京市" },
        { areaCode: "120000", area: "天津市" },
        { areaCode: "140100", area: "太原市" },
        { areaCode: "140200", area: "大同市" },
        { areaCode: "140300", area: "阳泉市" },
        { areaCode: "140400", area: "长治市" },
        { areaCode: "140500", area: "晋城市" },
        { areaCode: "140600", area: "朔州市" },
        { areaCode: "140700", area: "晋中市" },
        { areaCode: "140800", area: "运城市" },
        { areaCode: "140900", area: "忻州市" },
        { areaCode: "141000", area: "临汾市" },
        { areaCode: "141100", area: "吕梁市" },
        { areaCode: "150100", area: "呼和浩特市" },
        { areaCode: "150200", area: "包头市" },
        { areaCode: "150300", area: "乌海市" },
        { areaCode: "150400", area: "赤峰市" },
        { areaCode: "150500", area: "通辽市" },
        { areaCode: "150600", area: "鄂尔多斯市" },
        { areaCode: "150700", area: "呼伦贝尔市" },
        { areaCode: "150800", area: "巴彦淖尔市" },
        { areaCode: "150900", area: "乌兰察布市" },
        { areaCode: "152100", area: "呼伦贝尔盟" },
        { areaCode: "152200", area: "兴安盟" },
        { areaCode: "152300", area: "哲里木盟" },
        { areaCode: "152400", area: "昭乌达盟" },
        { areaCode: "152500", area: "锡林郭勒盟" },
        { areaCode: "152600", area: "乌兰察布盟" },
        { areaCode: "152700", area: "伊克昭盟" },
        { areaCode: "152800", area: "巴彦淖尔盟" },
        { areaCode: "152900", area: "阿拉善盟" },
        { areaCode: "210100", area: "沈阳市" },
        { areaCode: "210200", area: "大连市" },
        { areaCode: "210300", area: "鞍山市" },
        { areaCode: "210400", area: "抚顺市" },
        { areaCode: "210500", area: "本溪市" },
        { areaCode: "210600", area: "丹东市" },
        { areaCode: "210700", area: "锦州市" },
        { areaCode: "210800", area: "营口市" },
        { areaCode: "210900", area: "阜新市" },
        { areaCode: "211000", area: "辽阳市" },
        { areaCode: "211100", area: "盘锦市" },
        { areaCode: "211200", area: "铁岭市" },
        { areaCode: "211300", area: "朝阳市" },
        { areaCode: "211400", area: "葫芦岛市" },
        { areaCode: "220100", area: "长春市" },
        { areaCode: "220200", area: "吉林市" },
        { areaCode: "220300", area: "四平市" },
        { areaCode: "220400", area: "辽源市" },
        { areaCode: "220500", area: "通化市" },
        { areaCode: "220600", area: "白山市" },
        { areaCode: "220700", area: "松原市" },
        { areaCode: "220800", area: "白城市" },
        { areaCode: "230100", area: "哈尔滨市" },
        { areaCode: "230200", area: "齐齐哈尔市" },
        { areaCode: "230300", area: "鸡西市" },
        { areaCode: "230400", area: "鹤岗市" },
        { areaCode: "230500", area: "双鸭山市" },
        { areaCode: "230600", area: "大庆市" },
        { areaCode: "230700", area: "伊春市" },
        { areaCode: "230800", area: "佳木斯市" },
        { areaCode: "230900", area: "七台河市" },
        { areaCode: "231000", area: "牡丹江市" },
        { areaCode: "231100", area: "黑河市" },
        { areaCode: "231200", area: "绥化市" },
        { areaCode: "310000", area: "上海市" },
        { areaCode: "320100", area: "南京市" },
        { areaCode: "320200", area: "无锡市" },
        { areaCode: "320300", area: "徐州市" },
        { areaCode: "320400", area: "常州市" },
        { areaCode: "320500", area: "苏州市" },
        { areaCode: "320600", area: "南通市" },
        { areaCode: "320700", area: "连云港市" },
        { areaCode: "320800", area: "淮安市" },
        { areaCode: "320900", area: "盐城市" },
        { areaCode: "321000", area: "扬州市" },
        { areaCode: "321100", area: "镇江市" },
        { areaCode: "321200", area: "泰州市" },
        { areaCode: "321300", area: "宿迁市" },
        { areaCode: "330100", area: "杭州市" },
        { areaCode: "330200", area: "宁波市" },
        { areaCode: "330300", area: "温州市" },
        { areaCode: "330400", area: "嘉兴市" },
        { areaCode: "330500", area: "湖州市" },
        { areaCode: "330600", area: "绍兴市" },
        { areaCode: "330700", area: "金华市" },
        { areaCode: "330800", area: "衢州市" },
        { areaCode: "330900", area: "舟山市" },
        { areaCode: "331000", area: "台州市" },
        { areaCode: "331100", area: "丽水市" },
        { areaCode: "340100", area: "合肥市" },
        { areaCode: "340200", area: "芜湖市" },
        { areaCode: "340300", area: "蚌埠市" },
        { areaCode: "340400", area: "淮南市" },
        { areaCode: "340500", area: "马鞍山市" },
        { areaCode: "340600", area: "淮北市" },
        { areaCode: "340700", area: "铜陵市" },
        { areaCode: "340800", area: "安庆市" },
        { areaCode: "340900", area: "黄山市" },
        { areaCode: "341000", area: "黄山市" },
        { areaCode: "341100", area: "滁州市" },
        { areaCode: "341200", area: "阜阳市" },
        { areaCode: "341300", area: "宿州市" },
        { areaCode: "341400", area: "巢湖市" },
        { areaCode: "341500", area: "六安市" },
        { areaCode: "341600", area: "亳州市" },
        { areaCode: "341700", area: "池州市" },
        { areaCode: "341800", area: "宣城市" },
        { areaCode: "350100", area: "福州市" },
        { areaCode: "350200", area: "厦门市" },
        { areaCode: "350300", area: "莆田市" },
        { areaCode: "350400", area: "三明市" },
        { areaCode: "350500", area: "泉州市" },
        { areaCode: "350600", area: "漳州市" },
        { areaCode: "350700", area: "南平市" },
        { areaCode: "350800", area: "龙岩市" },
        { areaCode: "350900", area: "宁德市" },
        { areaCode: "360100", area: "南昌市" },
        { areaCode: "360200", area: "景德镇市" },
        { areaCode: "360300", area: "萍乡市" },
        { areaCode: "360400", area: "九江市" },
        { areaCode: "360500", area: "新余市" },
        { areaCode: "360600", area: "鹰潭市" },
        { areaCode: "360700", area: "赣州市" },
        { areaCode: "360800", area: "吉安市" },
        { areaCode: "360900", area: "宜春市" },
        { areaCode: "361000", area: "抚州市" },
        { areaCode: "361100", area: "上饶市" },
        { areaCode: "370100", area: "济南市" },
        { areaCode: "370200", area: "青岛市" },
        { areaCode: "370300", area: "淄博市" },
        { areaCode: "370400", area: "枣庄市" },
        { areaCode: "370500", area: "东营市" },
        { areaCode: "370600", area: "烟台市" },
        { areaCode: "370700", area: "潍坊市" },
        { areaCode: "370800", area: "济宁市" },
        { areaCode: "370900", area: "泰安市" },
        { areaCode: "371000", area: "威海市" },
        { areaCode: "371100", area: "日照市" },
        { areaCode: "371200", area: "莱芜市" },
        { areaCode: "371300", area: "临沂市" },
        { areaCode: "371400", area: "德州市" },
        { areaCode: "371500", area: "聊城市" },
        { areaCode: "371600", area: "滨州市" },
        { areaCode: "371700", area: "菏泽市" },
        { areaCode: "410100", area: "郑州市" },
        { areaCode: "410200", area: "开封市" },
        { areaCode: "410300", area: "洛阳市" },
        { areaCode: "410400", area: "平顶山市" },
        { areaCode: "410500", area: "安阳市" },
        { areaCode: "410600", area: "鹤壁市" },
        { areaCode: "410700", area: "新乡市" },
        { areaCode: "410800", area: "焦作市" },
        { areaCode: "410900", area: "濮阳市" },
        { areaCode: "411000", area: "许昌市" },
        { areaCode: "411100", area: "漯河市" },
        { areaCode: "411200", area: "三门峡市" },
        { areaCode: "411300", area: "南阳市" },
        { areaCode: "411400", area: "商丘市" },
        { areaCode: "411500", area: "信阳市" },
        { areaCode: "411600", area: "周口市" },
        { areaCode: "411700", area: "驻马店市" },
        { areaCode: "420100", area: "武汉市" },
        { areaCode: "420200", area: "黄石市" },
        { areaCode: "420300", area: "十堰市" },
        { areaCode: "420400", area: "沙市市" },
        { areaCode: "420500", area: "宜昌市" },
        { areaCode: "420600", area: "襄阳市" },
        { areaCode: "420700", area: "鄂州市" },
        { areaCode: "420800", area: "荆门市" },
        { areaCode: "420900", area: "孝感市" },
        { areaCode: "421000", area: "荆州市" },
        { areaCode: "421100", area: "黄冈市" },
        { areaCode: "421200", area: "咸宁市" },
        { areaCode: "421300", area: "随州市" },
        { areaCode: "422800", area: "恩施土家族苗族自治州" },
        { areaCode: "430100", area: "长沙市" },
        { areaCode: "430200", area: "株洲市" },
        { areaCode: "430300", area: "湘潭市" },
        { areaCode: "430400", area: "衡阳市" },
        { areaCode: "430500", area: "邵阳市" },
        { areaCode: "430600", area: "岳阳市" },
        { areaCode: "430700", area: "常德市" },
        { areaCode: "430800", area: "张家界市" },
        { areaCode: "430900", area: "益阳市" },
        { areaCode: "431000", area: "郴州市" },
        { areaCode: "431100", area: "永州市" },
        { areaCode: "431200", area: "怀化市" },
        { areaCode: "431300", area: "娄底市" },
        { areaCode: "432300", area: "益阳市" },
        { areaCode: "433100", area: "湘西土家族苗族自治州" },
        { areaCode: "440100", area: "广州市" },
        { areaCode: "440200", area: "韶关市" },
        { areaCode: "440300", area: "深圳市" },
        { areaCode: "440400", area: "珠海市" },
        { areaCode: "440500", area: "汕头市" },
        { areaCode: "440600", area: "佛山市" },
        { areaCode: "440700", area: "江门市" },
        { areaCode: "440800", area: "湛江市" },
        { areaCode: "440900", area: "茂名市" },
        { areaCode: "441000", area: "海口市" },
        { areaCode: "441200", area: "肇庆市" },
        { areaCode: "441300", area: "惠州市" },
        { areaCode: "441400", area: "梅州市" },
        { areaCode: "441500", area: "汕尾市" },
        { areaCode: "441600", area: "河源市" },
        { areaCode: "441700", area: "阳江市" },
        { areaCode: "441800", area: "清远市" },
        { areaCode: "441900", area: "东莞市" },
        { areaCode: "442000", area: "中山市" },
        { areaCode: "442100", area: "海南行政区" },
        { areaCode: "442200", area: "三亚市" },
        { areaCode: "445100", area: "潮州市" },
        { areaCode: "445200", area: "揭阳市" },
        { areaCode: "445300", area: "云浮市" },
        { areaCode: "450100", area: "南宁市" },
        { areaCode: "450200", area: "柳州市" },
        { areaCode: "450300", area: "桂林市" },
        { areaCode: "450400", area: "梧州市" },
        { areaCode: "450500", area: "北海市" },
        { areaCode: "450600", area: "防城港市" },
        { areaCode: "450700", area: "钦州市" },
        { areaCode: "450800", area: "贵港市" },
        { areaCode: "450900", area: "玉林市" },
        { areaCode: "451000", area: "百色市" },
        { areaCode: "451100", area: "贺州市" },
        { areaCode: "451200", area: "河池市" },
        { areaCode: "451300", area: "来宾市" },
        { areaCode: "451400", area: "崇左市" },
        { areaCode: "460100", area: "海口市" },
        { areaCode: "460200", area: "三亚市" },
        { areaCode: "460300", area: "三沙市" },
        { areaCode: "500000", area: "重庆市" },
        { areaCode: "510100", area: "成都市" },
        { areaCode: "510300", area: "自贡市" },
        { areaCode: "510400", area: "攀枝花市" },
        { areaCode: "510500", area: "泸州市" },
        { areaCode: "510600", area: "德阳市" },
        { areaCode: "510700", area: "绵阳市" },
        { areaCode: "510800", area: "广元市" },
        { areaCode: "510900", area: "遂宁市" },
        { areaCode: "511000", area: "内江市" },
        { areaCode: "511100", area: "乐山市" },
        { areaCode: "511300", area: "南充市" },
        { areaCode: "511400", area: "眉山市" },
        { areaCode: "511500", area: "宜宾市" },
        { areaCode: "511600", area: "广安市" },
        { areaCode: "511700", area: "达州市" },
        { areaCode: "511800", area: "雅安市" },
        { areaCode: "511900", area: "巴中市" },
        { areaCode: "512000", area: "资阳市" },
        { areaCode: "513200", area: "阿坝藏族羌族自治州" },
        { areaCode: "513300", area: "甘孜藏族自治州" },
        { areaCode: "513400", area: "凉山彝族自治州" },
        { areaCode: "520100", area: "贵阳市" },
        { areaCode: "520200", area: "六盘水市" },
        { areaCode: "520300", area: "遵义市" },
        { areaCode: "520400", area: "安顺市" },
        { areaCode: "520500", area: "毕节市" },
        { areaCode: "520600", area: "铜仁市" },
        { areaCode: "522300", area: "黔西南布依族苗族自治州" },
        { areaCode: "522600", area: "黔东南苗族侗族自治州" },
        { areaCode: "522700", area: "黔南布依族苗族自治州" },
        { areaCode: "530100", area: "昆明市" },
        { areaCode: "530200", area: "东川市" },
        { areaCode: "530300", area: "曲靖市" },
        { areaCode: "530400", area: "玉溪市" },
        { areaCode: "530500", area: "保山市" },
        { areaCode: "530600", area: "昭通市" },
        { areaCode: "530700", area: "丽江市" },
        { areaCode: "530800", area: "普洱市" },
        { areaCode: "530900", area: "临沧市" },
        { areaCode: "532300", area: "楚雄彝族自治州" },
        { areaCode: "532500", area: "红河哈尼族彝族自治州" },
        { areaCode: "532600", area: "文山壮族苗族自治州" },
        { areaCode: "532800", area: "西双版纳傣族自治州" },
        { areaCode: "532900", area: "大理白族自治州" },
        { areaCode: "533100", area: "德宏傣族景颇族自治州" },
        { areaCode: "533300", area: "怒江傈僳族自治州" },
        { areaCode: "533400", area: "迪庆藏族自治州" },
        { areaCode: "540100", area: "拉萨市" },
        { areaCode: "540200", area: "日喀则市" },
        { areaCode: "610100", area: "西安市" },
        { areaCode: "610200", area: "铜川市" },
        { areaCode: "610300", area: "宝鸡市" },
        { areaCode: "610400", area: "咸阳市" },
        { areaCode: "610500", area: "渭南市" },
        { areaCode: "610600", area: "延安市" },
        { areaCode: "610700", area: "汉中市" },
        { areaCode: "610800", area: "榆林市" },
        { areaCode: "610900", area: "安康市" },
        { areaCode: "611000", area: "商洛市" },
        { areaCode: "612300", area: "汉中市" },
        { areaCode: "620100", area: "兰州市" },
        { areaCode: "620200", area: "嘉峪关市" },
        { areaCode: "620300", area: "金昌市" },
        { areaCode: "620400", area: "白银市" },
        { areaCode: "620500", area: "天水市" },
        { areaCode: "620600", area: "武威市" },
        { areaCode: "620700", area: "张掖市" },
        { areaCode: "620800", area: "平凉市" },
        { areaCode: "620900", area: "酒泉市" },
        { areaCode: "621000", area: "庆阳市" },
        { areaCode: "621100", area: "定西市" },
        { areaCode: "621200", area: "陇南市" },
        { areaCode: "622900", area: "临夏回族自治州" },
        { areaCode: "623000", area: "甘南藏族自治州" },
        { areaCode: "630100", area: "西宁市" },
        { areaCode: "630200", area: "海东市" },
        { areaCode: "632200", area: "海北藏族自治州" },
        { areaCode: "632300", area: "黄南藏族自治州" },
        { areaCode: "632500", area: "海南藏族自治州" },
        { areaCode: "632600", area: "果洛藏族自治州" },
        { areaCode: "632700", area: "玉树藏族自治州" },
        { areaCode: "632800", area: "海西蒙古族藏族自治州" },
        { areaCode: "640100", area: "银川市" },
        { areaCode: "640200", area: "石嘴山市" },
        { areaCode: "640300", area: "吴忠市" },
        { areaCode: "640400", area: "固原市" },
        { areaCode: "640500", area: "中卫市" },
        { areaCode: "650100", area: "乌鲁木齐市" },
        { areaCode: "650200", area: "克拉玛依市" },
        { areaCode: "650300", area: "石河子市" },
        { areaCode: "652300", area: "昌吉回族自治州" },
        { areaCode: "652400", area: "伊犁哈萨克自治州" },
        { areaCode: "652700", area: "博尔塔拉蒙古自治州" },
        { areaCode: "652800", area: "巴音郭楞蒙古自治州" },
        { areaCode: "653000", area: "克孜勒苏柯尔克孜自治州" },
        { areaCode: "654000", area: "伊犁哈萨克自治州" },
        { areaCode: "659000", area: "自治区直辖县级行政区划" },
        { areaCode: "710000", area: "台湾省" },
        { areaCode: "810000", area: "香港特别行政区" },
        { areaCode: "820000", area: "澳门特别行政区" }
      ];
      
      // 使用Promise.all和批量处理来提高效率
      const promises = [];
      const batchSize = 10; // 每批处理的数量
      
      for (let i = 0; i < cityData.length; i += batchSize) {
        const batch = cityData.slice(i, i + batchSize);
        const batchPromises = batch.map(city => {
          return addFhMapWeather({
            area: city.area,
            areaCode: city.areaCode
          });
        });
        promises.push(Promise.all(batchPromises));
      }
      
      // 顺序执行每批请求
      promises.reduce((chain, currentPromise) => {
        return chain.then(() => currentPromise);
      }, Promise.resolve())
        .then(() => {
          this.loading = false;
          this.$modal.msgSuccess("导入成功");
          this.getList();
        })
        .catch(error => {
          this.loading = false;
          this.$modal.msgError("导入失败: " + error.message);
        });
    },
    /** 查询城市天气管理列表 */
    getList() {
      this.loading = true;
      const {pageNum, pageSize} = this.queryParams;
      const query = {...this.queryParams, pageNum: undefined, pageSize: undefined};
      const pageReq = {page: pageNum - 1, size: pageSize};
      listFhMapWeather(query, pageReq).then(response => {
        const { content, totalElements } = response
        this.FhMapWeatherList = content;
        this.total = totalElements;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        area: null,
        areaCode: null,
        crateTime: null,
        userId: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加城市天气管理";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getFhMapWeather(id).then(response => {
        this.form = response;
        this.open = true;
        this.title = "修改城市天气管理";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateFhMapWeather(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addFhMapWeather(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除城市天气管理编号为"' + ids + '"的数据项？').then(function() {
        return delFhMapWeather(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$modal.confirm('是否确认导出所有城市天气管理数据项？').then(() => {
        this.exportLoading = true;
        return exportFhMapWeather(queryParams);
      }).then(response => {
        this.$download.download(response);
        this.exportLoading = false;
      }).catch(() => {});
    }
  }
};
</script>
